package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index(){
        String str = null;
        System.out.println(str.length());
        return "index";
    }

    /**
     * 可以设置异常范围控制捕获内容
     * @param e
     * @return
     */
    /*@ExceptionHandler({ Exception.class })
    public String testArithmeticException(Exception e) {
        System.out.println("打印错误信息 ===> Exception:" + e);
        // 跳转到指定页面
        return "redirect:/error?msg="+e;
    }*/

    /*@ExceptionHandler({Exception.class})
    public ModelAndView exception(Exception e){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("msg",e);
        return mv;
    }*/

    @RequestMapping("/error")
    public String error(String msg, Model model){
        model.addAttribute("msg",msg);
        return "error";
    }

}
